from flask import Flask, request, make_response
from werkzeug.utils import secure_filename

app = Flask(__name__)

@app.route('/login', methods=['POST', 'GET'])
def login():
    if request.method == 'POST':
        return request.form['username'] + " login with pwd " + request.form['password']
    else:
        searchword = request.args.get('key', '')
        return "search: " + searchword

@app.route('/upload', methods=['POST'])
def upload_file():
    f = request.files['the_file']
    f.save('/tmp/' + secure_filename(f.filename))
    return "ok"

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        username = request.cookies.get('username', '')
        return username
    else:
        resp = make_response()
        resp.set_cookie('username', 'the username')
        return resp



if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000, debug=True)